##
# license
snippet //l
	#
	#           ┌┬┐┬ ┬┌─┐┬ ┬┌─┐┌─┐┌┐┌
	#            │ └┬┘├─┘├─┤│ ││ ││││
	#            ┴  ┴ ┴  ┴ ┴└─┘└─┘┘└┘
	#
	# This file is part of the typhoon Project.
	# Copyright (C) 2021 stanley0207@163.com
	#
	# This program is free software: you can redistribute it and/or modify
	# it under the terms of the GNU General Public License as published by
	# the Free Software Foundation, either version 3 of the License, or
	# (at your option) any later version.
	#
	# This program is distributed in the hope that it will be useful,
	# but WITHOUT ANY WARRANTY; without even the implied warranty of
	# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	# GNU General Public License for more details.
	#
	# You should have received a copy of the GNU General Public License
	# along with this program.  If not, see <http://www.gnu.org/licenses/>.
	#
	
	${0}

##
# project
snippet proj
	project(${0:Name})

##
# cmake_minimum_required
snippet min
	cmake_minimum_required(VERSION ${0:3.20.0})

snippet include
	include_directories(${${0:include_dir}})

snippet find
	find_package(${1:library} ${0:REQUIRED})

snippet glob
	file(glob ${1:srcs} *.${0:cpp})

snippet subdir
	add_subdirectory(${0:src})

snippet lib
	add_library(${1:lib} ${${0:srcs}})

snippet link
	target_link_libraries(${1:bin} ${0:somelib})

snippet bin
	add_executable(${1:bin})

snippet set
	set(${1:var} ${0:val})

snippet dep
	add_dependencies(${1:target}
		${0:dep}
	)

snippet Ext_url
	include(ExternalProject)
	ExternalProject_Add(${1:googletest}
	  URL ${2:http://googletest.googlecode.com/files/gtest-1.7.0.zip}
	  URL_HASH SHA1=${3:f85f6d2481e2c6c4a18539e391aa4ea8ab0394af}
	  SOURCE_DIR "${4:${CMAKE_BINARY_DIR}/gtest-src}"
	  BINARY_DIR "${0:${CMAKE_BINARY_DIR}/gtest-build}"
	  CONFIGURE_COMMAND ""
	  BUILD_COMMAND     ""
	  INSTALL_COMMAND   ""
	  TEST_COMMAND      ""
	)

snippet Ext_git
	include(ExternalProject)
	ExternalProject_Add(${1:googletest}
	  GIT_REPOSITORY    ${2:https://github.com/google/googletest.git}
	  GIT_TAG           ${3:master}
	  SOURCE_DIR        "${4:${CMAKE_BINARY_DIR}/googletest-src}"
	  BINARY_DIR        "${0:${CMAKE_BINARY_DIR}/googletest-build}"
	  CONFIGURE_COMMAND ""
	  BUILD_COMMAND     ""
	  INSTALL_COMMAND   ""
	  TEST_COMMAND      ""
	)

snippet props
	set_target_properties(${1:target}
		${2:properties} ${3:compile_flags}
		${0:"-O3 -Wall -pedantic"}
	)

snippet test
	add_test(${1:ATestName} ${0:testCommand --options})

snippet catch
	#
	#           ┌┬┐┬ ┬┌─┐┬ ┬┌─┐┌─┐┌┐┌
	#            │ └┬┘├─┘├─┤│ ││ ││││
	#            ┴  ┴ ┴  ┴ ┴└─┘└─┘┘└┘
	#
	# This file is part of the typhoon Project.
	# Copyright (C) 2021 stanley0207@163.com
	#
	# This program is free software: you can redistribute it and/or modify
	# it under the terms of the GNU General Public License as published by
	# the Free Software Foundation, either version 3 of the License, or
	# (at your option) any later version.
	#
	# This program is distributed in the hope that it will be useful,
	# but WITHOUT ANY WARRANTY; without even the implied warranty of
	# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	# GNU General Public License for more details.
	#
	# You should have received a copy of the GNU General Public License
	# along with this program.  If not, see <http://www.gnu.org/licenses/>.
	#

	cmake_minimum_required(VERSION ${1:3.20.0})

	project(test_${2:module_name} ${3:CXX})

	add_executable(test_$2
		"../../test_include.h"
		"../../test_main.cpp"
		"test_${4:$2}.cpp"
	)

	set_property(TARGET
		test_$2
		APPEND
		PROPERTY
			COMPILE_DEFINITIONS
			${5}
	)

	target_link_libraries(test_$2
		Catch2::Catch2
		${0}
	)

	install(TARGETS test_$2 DESTINATION \${BIN_DIR}/tests)
	include(CTest)
	include(Catch)
	catch_discover_tests(test_$2)

snippet module
	#
	#           ┌┬┐┬ ┬┌─┐┬ ┬┌─┐┌─┐┌┐┌
	#            │ └┬┘├─┘├─┤│ ││ ││││
	#            ┴  ┴ ┴  ┴ ┴└─┘└─┘┘└┘
	#
	# This file is part of the typhoon Project.
	# Copyright (C) 2021 stanley0207@163.com
	#
	# This program is free software: you can redistribute it and/or modify
	# it under the terms of the GNU General Public License as published by
	# the Free Software Foundation, either version 3 of the License, or
	# (at your option) any later version.
	#
	# This program is distributed in the hope that it will be useful,
	# but WITHOUT ANY WARRANTY; without even the implied warranty of
	# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	# GNU General Public License for more details.
	#
	# You should have received a copy of the GNU General Public License
	# along with this program.  If not, see <http://www.gnu.org/licenses/>.
	#

	# collect source
	CollectSourceFiles(
		${CMAKE_CURRENT_SOURCE_DIR\}
		PRIVATE_SOURCES
		# Exclude
		${CMAKE_CURRENT_SOURCE_DIR\}/pch
		)

	# collect include
	CollectIncludeDirectories(
		${CMAKE_CURRENT_SOURCE_DIR\}
		PUBLIC_INCLUDES
		# Exclude
		${CMAKE_CURRENT_SOURCE_DIR\}/pch
		)

	# source tree
	GroupSources(${CMAKE_CURRENT_SOURCE_DIR\})

	# library $1
	add_library(${1:moudle_name}
		${PRIVATE_SOURCES\}
		)

	# include
	target_include_directories($1
		PRIVATE
			${CMAKE_CURRENT_BINARY_DIR\}
		PUBLIC
			${PUBLIC_INCLUDES\}
		)

	# link
	target_link_libraries($1
		PRIVATE
			typhoon-core-interface
		PUBLIC
			$0
		)

	# export
	add_definitions(-DTPN_API_EXPORT_${2:$1})

	# ide folder
	set_target_properties($1
		PROPERTIES
			FOLDER
				"libs"
		)

	# shared library
	if(BUILD_SHARED_LIBS)
		install(TARGETS
			$1
			LIBRARY
				DESTINATION
					${BIN_DIR\}/lib
			)
	endif()

	# pch
	if(USE_COREPCH)
		target_precompile_headers($1
			PRIVATE
				${CMAKE_CURRENT_SOURCE_DIR\}/pch/pch_$1.h
			)
	endif()

snippet exec
	#
	#           ┌┬┐┬ ┬┌─┐┬ ┬┌─┐┌─┐┌┐┌
	#            │ └┬┘├─┘├─┤│ ││ ││││
	#            ┴  ┴ ┴  ┴ ┴└─┘└─┘┘└┘
	#
	# This file is part of the typhoon Project.
	# Copyright (C) 2021 stanley0207@163.com
	#
	# This program is free software: you can redistribute it and/or modify
	# it under the terms of the GNU General Public License as published by
	# the Free Software Foundation, either version 3 of the License, or
	# (at your option) any later version.
	#
	# This program is distributed in the hope that it will be useful,
	# but WITHOUT ANY WARRANTY; without even the implied warranty of
	# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	# GNU General Public License for more details.
	#
	# You should have received a copy of the GNU General Public License
	# along with this program.  If not, see <http://www.gnu.org/licenses/>.
	#

	# collect source
	CollectSourceFiles(
		${CMAKE_CURRENT_SOURCE_DIR\}
		PRIVATE_SOURCES
		# Exclude
		${CMAKE_CURRENT_SOURCE_DIR\}/pch
		)

	# collect include
	CollectIncludeDirectories(
		${CMAKE_CURRENT_SOURCE_DIR\}
		PUBLIC_INCLUDES
		# Exclude
		${CMAKE_CURRENT_SOURCE_DIR\}/pch
		)

	# source tree
	GroupSources(${CMAKE_CURRENT_SOURCE_DIR\})

	# executable $1
	add_executable(${1:moudle_name}
		${PRIVATE_SOURCES\}
		)

	# include
	target_include_directories($1
		PRIVATE
			${CMAKE_CURRENT_BINARY_DIR\}
		PUBLIC
			${PUBLIC_INCLUDES\}
		)

	# link
	target_link_libraries($1
		PRIVATE
			typhoon-core-interface
		PUBLIC
			$0
		)

	# ide folder
	set_target_properties($1
		PROPERTIES
			FOLDER
				"${2:server}"
		)

	# install
	install(TARGETS
		$1
			DESTINATION
				${BIN_DIR\}
		)

	# pch
	if(USE_COREPCH)
		target_precompile_headers($1
			PRIVATE
				${CMAKE_CURRENT_SOURCE_DIR\}/pch/pch_$1.h
			)
	endif()
